#!/bin/bash

if [ $# -lt 1 ]; then
	echo "Usage: $0 function [cflow options]"
	exit 0
fi

. ./config
FUNC_NAME=$1
CFLOW_OPTIONS=$2
PNG_FILE="$OBJ_PATH/$FUNC_NAME.png"
DOT_FILE="$OBJ_PATH/$FUNC_NAME.dot"

if [ ! -d $OBJ_PATH ]; then
	mkdir -p $OBJ_PATH
fi

if [ -z "$CFLOW_OPTIONS" ]; then
	./cflow_pic.sh "$FUNC_NAME" $SRC_LIST > "${DOT_FILE}"
else
	./cflow_pic.sh main $CFLOW_OPTIONS "$FUNC_NAME" $SRC_LIST > "${DOT_FILE}"
fi

dot -Tpng -o "${PNG_FILE}" "$DOT_FILE"

echo "OUT_DOT_FILE: \"${DOT_FILE}"
echo "OUT_PNG_FILE: \"${PNG_FILE}"

if [ -n "$PIC_TOOLS" ]; then
	$PIC_TOOLS "$PNG_FILE" >/dev/null 2>&1
fi
